import { observable, action, configure, toJS, runInAction } from 'mobx';
import { getMenu, getString } from '@/services/menu';

configure({ enforceActions: 'observed' });

class AppStore {
  constructor() {
    this.toJS = toJS;
  }

  // 菜单资源
  @observable menuList = [];

  @action.bound
  setStore(key, data) {
    this[key] = data;
  }

  // 请求菜单数据
  @action.bound
  async reqMenu() {
    const res = await getMenu();

    res &&
      runInAction(() => {
        if (res.resultCode === 0) {
          this.menuList = res.data.list;
        }
      });
  }

  // 请求菜单数据
  @action.bound
  async reqString() {
    const res = await getString();

    res &&
      runInAction(() => {
        if (res.resultCode === 0) {
          this.menuList = res.data.list;
        }
      });
  }
}

export default new AppStore();
